<template>
  <div class="search">
    <a-modal :visible="modalVisible" :title="modalTitle" width="550px" @ok="handleSubmit" @cancel="modalVisible=false"
             :mask="false">
      <f-form ref="form" :action="api.report" :form-key="this.formItem.reportId" @success="onSuccess">
        <f-form-item ref="supplierInfo" label="分包商" type="select" name="supplierId" :autoLoad="true"
                     :data="api.report.getBusProjectAllSupplier"
                     label-key="supplierName,supplierNum,restSupplierNum"
                     :params="supplierInfoParams"
                     value-key="supplierId" :value="formItem.supplierId" :showSearch="true" @change="supplierChange"/>
        <f-form-item label="申报数量" name="declareQuantity" :value="formItem.declareQuantity"/>
        <f-form-item label="确认数量" name="confirmQuantity" :value="formItem.confirmQuantity"/>
        <f-form-item label="填报月份" name="reportMonth" type="month" :value="formItem.reportMonth"/>
      </f-form>
    </a-modal>
  </div>
</template>
<script>
  import api from './js/apiReport'

  export default {
    name: 'reportFormModal',
    data() {
      return {
        refs: this.refs,
        api: Object.assign(api, this.api),
        isAdd: true,//是否是添加模式
        loaded: false,//是否加载完成
        formItem: this.getFormItem(),
        supplierList: [{ supplierLabel: '包商1', supplierId: 1 }, { supplierLabel: '包商2', supplierId: 2 }],
        reportMonth: '',
        modalVisible: false,
        title: '填报月报',
        supplierInfoParams:{}
      }
    },
    methods: {
      getFormItem() {
        return {
          reportId: '',
          projectId: '',
          materialId: '',
          supplierId: '',
          declareQuantity: '',
          confirmQuantity: '',
          reportMonth: '',
          userId: '',
          createTime: '',
          updateTime: ''
        }
      },
      //表单赋值
      setData(data, supplierInfoParams) {
        this.modalVisible = true
        this.supplierInfoParams = supplierInfoParams
        this.$refs['form'].resetFields()
        this.formItem = this.getFormItem()

        if (data && data.reportId) {
          let params = {
            reportId: data.reportId
          }
          this.refs['form'].getDetails(params, (data) => {
            this.formItem = data
            this.loaded = true
          })
          this.isAdd = false
        } else {
          this.loaded = true
        }
      },
      //提交表单
      handleSubmit() {
        this.$refs.form.submit(this.supplierInfoParams)
      },
      supplierChange(value) {
        console.log(value)
      },
      handleShow(data) {
        this.formItem = this.getFormItem()
        let supplierInfoParams = {
          projectId: data.projectId,
          packageNo: data.packageNo,
          majorCode: data.majorCode,
          materialId: data.materialId,
          versionId: data.versionId,
          materialPackage100Id: data.materialPackage100Id
        }
        this.setData(data, supplierInfoParams)
      },
      onSuccess() {
        this.modalVisible = false
      }
    },
    computed: {
      modalTitle: function() {
        return this.title
      }
    },
    created() {
    },
    components: {}
  }
</script>

<style scoped lang="less" rel="stylesheet/less">

</style>
